<?php

require_once dirname(__FILE__).'/../../symfony_1_4/lib/autoload/sfCoreAutoload.class.php';
sfCoreAutoload::register();

class ProjectConfiguration extends sfProjectConfiguration
{
  private $frontendCacheManager=null;
  static protected $zendAutoloader = false;
  
  public function setup()
  {
    $this->enablePlugins('sfDoctrinePlugin');
    $this->enablePlugins('sfDoctrineGuardPlugin');
    $this->enablePlugins('sfFormExtraPlugin');
    $this->enablePlugins('sfDoctrineApplyPlugin');
    
    //self::registerZend();
  }
  
  static public function registerZend()  
  {  
    if(!self::$zendAutoloader)  
    {  
      set_include_path(implode(  
        PATH_SEPARATOR,  
        array(sfConfig::get('sf_lib_dir') . '/vendor', get_include_path())
      ));
      require_once 'Zend/Loader/Autoloader.php';
      self::$zendAutoloader = Zend_Loader_Autoloader::getInstance();
    }
  
    return self::$zendAutoloader;  
  }
	public function getFrontendInstance(){
	  	$current=sfContext::getInstance()->getConfiguration()->getApplication();
	  	if($current=="frontend"){
	  		return sfContext::getInstance();
	  	}
	  	if(sfContext::hasInstance("frontend")){
	  		return sfContext::getInstance("frontend");
	  	}else{
		  	$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', sfConfig::get('sf_environment'), sfConfig::get("sf_debug"));
			sfContext::createInstance($configuration);
			sfContext::switchTo($current);
	  	}
	  	
	  	return sfContext::getInstance("frontend");
  }
  public function configureDoctrine(Doctrine_Manager $manager)
  {
    $manager->setAttribute(Doctrine_Core::ATTR_RESULT_CACHE, new Doctrine_Cache_Array());
  }
}
